package yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import yunhe.biz.StockMgrBiz;
import yunhe.biz.impl.StockMgrBizImpl;
import yunhe.util.GeneralUtil;

@WebServlet(name="SaveProLossMsgServlet",urlPatterns="/SaveProLossMsgServlet")
public class SaveProLossMsgServlet extends HttpServlet
{
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException
{
	doPost(req,resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{ 
	   StockMgrBiz stock=new StockMgrBizImpl();   
	   String takId=req.getParameter("takId");
		String stoName=req.getParameter("stoName");
		//根据仓库名称获得仓库id
		String stoId=stock.queryStoByName(stoName).get(0).getStoId();	
        String proBarCode=req.getParameter("proBarCode");
        //报损数量
		String proNum=req.getParameter("proNum");
		int reportnum=Integer.parseInt(proNum);	
		String countMoney=req.getParameter("countPrice");
		String lossReason=req.getParameter("lossReason");
		String proLossNum=req.getParameter("proLossNum");
		//如果损益数量小与0
		if(Integer.parseInt(proLossNum)<0)
		  //将报损数量设置为负值
			 reportnum=-reportnum;
		 //获得主键序列		
		String proLossId=GeneralUtil.creatSeq("SY");
		Object[] params={proLossId,takId,stoId,proBarCode,reportnum,countMoney,lossReason};	
		int m=stock.insertToProLoss(params);
		
		
		PrintWriter out=resp.getWriter();
		if(m>0)
			out.print("报损成功");
		//存入报损单
	
	}
}
